﻿using Abp.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.AutoMapper;

namespace MyCompanyName.AbpZeroTemplate.Prm.Admin
{
    public class RdCenterAppService : AbpZeroTemplateAppServiceBase, IRdCenterAppService
    {
        IRepository<RdCenter, int> rdCenterRepository;


        public RdCenterAppService(IRepository<RdCenter, int> _rdCenterRepository)
        {
            rdCenterRepository = _rdCenterRepository;
        }

        public List<Dto.GetRdCenterOutPut> GetAll()
        {
            var all = rdCenterRepository.GetAll();
            var model = all.MapTo<List<Dto.GetRdCenterOutPut>>();
            return model;
        }


        public async Task CreateOrEdit(Dto.CreateOrEditRdCenterInPut input)
        {
            var rd = new RdCenter();
            if (input.Id > 0)
            {
                rd = await rdCenterRepository.GetAsync(input.Id);
            }
            else
            {
                await rdCenterRepository.InsertAsync(rd);
            }
            rd.Name = input.Name;
            rd.Principal = input.Principal;
            rd.BusinessId = input.BusinessId;
        }


        public async Task<Dto.GetRdCenterOutPut> Get(int rdCenterId)
        {
            var rd = await rdCenterRepository.GetAsync(rdCenterId);
            var model = rd.MapTo<Dto.GetRdCenterOutPut>();
            return model;
        }


        public List<Dto.GetRdCenterOutPut> GetByBusinessId(int businessId)
        {
            var all = rdCenterRepository.GetAll().Where(x => x.BusinessId == businessId);
            var model = all.MapTo<List<Dto.GetRdCenterOutPut>>();
            return model;
        }


        public async Task Delete(int rdCenterId)
        {
            await rdCenterRepository.DeleteAsync(rdCenterId);
        }
    }
}
